﻿/* * 版 本 PIT-ADMS V7.0.3 敏捷开发框架
 * Copyright (c) 2013-2018 Hexagon PPM
 * 创建人：超级管理员
 * 日  期：2022-02-09 22:05
 * 描  述：样板目录
 */
var acceptClick;
var keyValue = request('keyValue');
var ProjectId = request('ProjectId');
var UpTemplateCatalogueID = request('UpTemplateCatalogueID');
var bootstrap = function ($, learun) {
    "use strict";
    var page = {
        init: function () {
            page.bind();
            page.initData();
        },
        bind: function () {
            $('#UpTemplateCatalogueID').lrselect({
                url: top.$.rootUrl + '/ZZDT_EC/ec_template_catalogue/GetTreeData',
                param: { ProjectId: ProjectId, TemplateCatalogueID: keyValue },
                type: 'tree',
                allowSearch: true,
                maxHeight: 225
            }).lrselectSet(UpTemplateCatalogueID);

        },
        initData: function () {
            if (!!keyValue) {
                $.lrSetForm(top.$.rootUrl + '/ZZDT_EC/ec_template_catalogue/GetFormData?keyValue=' + keyValue + "&ProjectId=" + ProjectId, function (data) {
                    for (var id in data) {
                        if (!!data[id] && data[id].length > 0) {
                            $('#' + id).jfGridSet('refreshdata', data[id]);
                        }
                        else {
                            $('[data-table="' + id + '"]').lrSetFormData(data[id]);
                        }
                    }
                });
            }
        }
    };
    // 保存数据
    acceptClick = function (callBack) {
        if (!$('#form').lrValidform()) {
            return false;
        }
        //文字特殊字符及最大长度检测
        if (!verify()) {
            return false;
        }
        var formData = $('#form').lrGetFormData();
        if (!formData.UpTemplateCatalogueID) {
            formData.UpTemplateCatalogueID = '0';
        }
        if (!keyValue) {
            formData.ProjectId = ProjectId;
        }
        var postData = {
            strEntity: JSON.stringify(formData)
        }
        $.lrSaveForm(top.$.rootUrl + '/ZZDT_EC/ec_template_catalogue/SaveForm?keyValue=' + keyValue + "&ProjectId=" + ProjectId, postData, function (res) {
            // 保存成功后才回调
            if (!!callBack) {
                callBack();
            }
        });
    };
    page.init();
}
//文字特殊字符及最大长度检测
function verify() {
    var msg = checkStr($("#TemplateCatalogueName").val(), 200);
    if (msg) {
        $.lrValidformMessage($("#TemplateCatalogueName"), msg);
        $('#TemplateCatalogueName').click();
        return false;
    }
    return true;
}